﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
using System.Globalization;
using System.Windows.Media;
using ReporterEngine.Model;

namespace Reporter.Converters
{
    [ValueConversion(typeof(string), typeof(string))]
    public class MaxTextLengthConverter : IValueConverter
    {
        public int MaxTextLength { get; set; }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value == null)
                return null;

            var sourceText = value.ToString();
            if (sourceText.Length > MaxTextLength)
            {
                return string.Concat(sourceText.Substring(0, MaxTextLength), "...");
            }
            return sourceText;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
